package com.news.service.impl;


import com.news.dao.NewsDao;
import com.news.dao.impl.NewsDaoImpl;
import com.news.pojo.News;
import com.news.pojo.Page;
import com.news.service.NewsSerice;

import java.util.List;

public class NewsSericeImpl implements NewsSerice {
    private NewsDao newsDao = new NewsDaoImpl();
    /**
     * 添加新闻内容
     *
     * @param news
     * @return
     * @throws RuntimeException
     */
    @Override
    public boolean addNews(News news) throws RuntimeException {
                return newsDao.addNews(news)==1?true:false;
                }

/**
 * 删除新闻内容
 *
 * @param nid
 * @return
 * @throws RuntimeException
 */
@Override
public boolean delNews(int nid) throws RuntimeException {
        return newsDao.delNews(nid)==1?true:false;
        }


/**
 * 查询所有新闻
 *
 * @return
 * @throws RuntimeException
 */
@Override
public List<News> getAllNews() throws RuntimeException {
        return newsDao.getAllNews();
        }

/**
 * 通过id查询新闻
 *
 * @param nid
 * @return
 * @throws RuntimeException
 */
@Override
public News getByIdNews(int nid) throws RuntimeException {
        return newsDao.getByIdNews(nid);
        }

    /**
     * 分页查询（1.所有  2.指定）
     *
     * @param page
     * @param news
     * @return
     * @throws RuntimeException
     */
    @Override
    public Page<News> getNewsByPage(Page<News> page, News news) throws RuntimeException {
        //新闻的总条数
        page.setTotalCount(newsDao.getCount(news));
        //新闻数据
        page.setData(newsDao.getNewsByPage(page.getCurrPageNo(),page.getPageSize(),news));
        return page;
    }
}
